<?
$url=$_SERVER['HTTP_HOST'].$_SERVER['QUERY_STRING']; 
if (eregi("Enquiry.php",$url)) {	
die("&nbsp;");
}
 
$template_body="template/enqui.tpl";
 
$base_url 	= 'index.php';
$url= substr($url,strpos($url,".php"),strlen($url));
$url=explode("/",$url);

 $mode=$url[2] ; 
 
 switch($mode){ 
  
  case "send":
 	  sendContact();
	  break; 
  default:
	  viewcontact(); 
	  break; 
 } 
 
function sendContact(){
	global $db,$template,$site_base_href;
	
	$txtSubject=isset($_POST["txtSubject"]) ? htmlspecialchars($_POST["txtSubject"]) : ' '; 
	$txtMessage=isset($_POST["txtMessage"]) ? htmlspecialchars($_POST["txtMessage"]) : ' ';	
	$txtFirsName=isset($_POST["txtFirsName"]) ? htmlspecialchars($_POST["txtFirsName"]) : ' '; 	 
	$txtCompany=isset($_POST["txtCompany"]) ? htmlspecialchars($_POST["txtCompany"]) : ' '; 
	$txtAddress=isset($_POST["txtAddress"]) ? htmlspecialchars($_POST["txtAddress"]) : ' ';
	$txtEmail=isset($_POST["txtEmail"]) ? htmlspecialchars($_POST["txtEmail"]) : ' ';		
	$txtBussinessPhone=isset($_POST["txtBussinessPhone"]) ? htmlspecialchars($_POST["txtBussinessPhone"]) : ' ';	
	$contactID=isset($_POST["contactID"]) ? intval($_POST["contactID"]) : 0;
	$sql="select AlternativeEmail from vb_memberprofile where memID=".$contactID;	
	$cusEmail=$db->getRecord($sql);
	
		require_once("class/email.php");
		$filecontent="<strong>Subject</strong> :  $txtSubject <br>";
		$filecontent.="<strong>Full Name</strong> : $txtFirsName <br>";
		$filecontent.="<strong>Company</strong> : $txtCompany <br>";
		$filecontent.="<strong>Address</strong> : $txtAddress <br>";
		$filecontent.="<strong>Email</strong> : $txtEmail <br>";
		$filecontent.="<strong>Phone</strong> : $txtBussinessPhone <br>";
		$filecontent.="<strong>Contents</strong> :<br> $txtMessage <br>";
		
		$mail= new email();	
		$mail->to =$cusEmail;
		$mail->toname =' ';
		$mail->fromname ="YellowPages";
		$mail->from = "support@yellowpages.vn";
		$mail->enable_html = true;				
		$mail->subject = "YellowPages.vn";
		$mail->body = $filecontent;		
		 
		 $mail->send();		
		echo '<TITLE>YellowPages.vn - Vietnam Business Yellow Pages Directory - Trang Vang Vietnam</TITLE><br><br><br> <div align="center" class="quote">Thank you for contacting us. We will reply  as soon as possible.</div>'; 
		return;
} 
function viewcontact(){
	global $template,$template_body,$site_base_href ,$base_url,$url;
	
	$i=rand(4,5);
	for($j=0;$j<$i;$j++){
	 $id_random .= chr(rand(65,90));
	}

	$cust= $url[3] ;
	$template->assign_vars(array( 
		'contactID' =>$cust,
		's_action'	=>$site_base_href."/index.php?/Enquiry/send/",		
		'ranima' => base64_encode(base64_encode($id_random)),
		'hdranima' =>$id_random,
		'getImage' =>$site_base_href.'/',
	));
	
	$template->set_filenames(array(
		'body' =>$template_body
		));
	$template->pparse('body');		
 

}
 
?>